<?php include COMMON_PATH.'/header.html'; ?>
<div class="page page_memberinfo">
  <div class="weui-body">
    <div class="weui-cells">
      <div class="weui-cell weui-cell_access selectfile" id="logo">
        <div class="weui-cell__hd">
          <p>店铺logo</p>
        </div>
        <div class="weui-cell__bd"></div>
        <div class="weui-cell__ft">
          <div class="avatar-wrapper">
            <img src="/res/mobile/images/shop_logo.png" alt="头像" class="pic" data-info="logo">
          </div>
        </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__hd">
          <p>店铺名称</p>
        </div>
        <div class="weui-cell__bd" data-info="name"></div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__hd">
          <p>店铺类型</p>
        </div>
        <div class="weui-cell__bd" data-info="type"></div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__hd">
          <p>经营地址</p>
        </div>
        <div class="weui-cell__bd" data-info="address"></div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__hd">
          <p>电子邮箱</p>
        </div>
        <div class="weui-cell__bd" data-info="email"></div>
      </div>
      <a class="weui-cell weui-cell_access" href="/mobile/store/validation">
        <div class="weui-cell__hd">
          <p>店铺资质</p>
        </div>
        <div class="weui-cell__bd">查看资质</div>
        <div class="weui-cell__ft"></div>
      </a>
    </div>
    <div class="weui-cells">
      <div class="weui-cell">
        <div class="weui-cell__hd">
          <p>主营业务</p>
        </div>
        <div class="weui-cell__bd">
          <input type="text" class="weui-input" placeholder="请输入主营业务" data-info="main">
        </div>
      </div>
    </div>
    <div class="longer-btn-wrapper">
      <a href="javascript:;" class="weui-btn" id="save">保存</a>
    </div>
    <!-- 上传头像 -->
    <input type="hidden" id="picfolder" value="touxiang">
    <input type="radio" hidden="hidden" name="myradio" value="random_name">
  </div>
</div>
<?php include COMMON_PATH.'/footer.html'; ?>
<script src="/res/mobile/js/plupload/plupload.full.min.js"></script>
<script src="/res/mobile/js/plupload/upload.js"></script>
<script>
  $(function() {
    function getData(field) {
      var loading = weui.loading();
      $.ajax({
        url: '/mobile/store/getstoreInfo',
        dataType: 'json',
        type: 'POST',
        data: field,
        success: function(res) {
          if (res.code == 1) {
            var data = res.data;
            $('[data-info="logo"]').attr('src', data.logoImg ? data.logoImg : '/res/mobile/images/attest/default-avatar.png');
            $('[data-info="name"]').text(data.storesName);
            $('[data-info="type"]').text(data.shop_type == 1 ? '专营店' : (data.shop_type == 2 ? '旗舰店' : '未认证'));
            $('[data-info="address"]').text(data.province + data.city);
            $('[data-info="email"]').text(data.email);
            $('[data-info="main"]').val(data.mainBuiness);
          } else {
            weui.topTips(res.msg)
          }
        },
        complete: function() {
          loading.hide();
        }
      })
    }
    getData();
    //保存
    $('#save').on('click', function() {
      var field = {
        logoImage: $('[data-info="logo"]').data('src'),
        mainBuiness: $('[data-info="main"]').val()
      }
      if (!field.mainBuiness) {
        weui.topTips('请填写主营业务');
        return false;
      }
      var loading = weui.loading();
      $.ajax({
        url: '/mobile/store/updatestore',
        dataType: 'json',
        type: 'POST',
        data: field,
        success: function(res) {
          if (res.code == 1) {
            weui.toast(res.msg);
            setTimeout(() => {
              window.location.href = '/mobile/member/index'
            }, 1000);
          } else {
            weui.topTips(res.msg)
          }
        },
        complete: function() {
          loading.hide();
        }
      })
    })
  })
</script>